﻿using System;
using Emico.Data.Entity.Repository;
using Emico.Data.Repository;


namespace Emico.Data.Entity.Tests.Repository
{
	#region Define

	public partial interface ITestContextUnitOfWork : IUnitOfWork
	{
	}
	
    public partial interface IBaseRepository : IRepository<Base>
	{
	}

	
    public partial interface IDerivedARepository : IRepository<DerivedA>
	{
	}

	
    public partial interface IDerivedBRepository : IRepository<DerivedB>
	{
	}

	
    public partial interface ISimpleRepository : IRepository<Simple>
	{
	}

	#endregion

	#region Implements

    namespace Imples   
    {
		public partial class TestContextUnitOfWork : DbUnitOfWork<TestContext>, ITestContextUnitOfWork
		{
			private Func<Type, IDbContextWrapper, IRepository> _resolver;

			public TestContextUnitOfWork(TestContext context)
				: base(context)
			{
			}

			public TestContextUnitOfWork(IDbContextWrapper wrapper)
				: base(wrapper)
			{
			}

            public override T GetRepository<T>()
            {
                T repository = default(T);
                if (this._resolver != null)
                {
                    repository = (T)this._resolver(typeof(T), this.Wrapper);
                }
                return repository;
            }

            public void SetRepositoryResolver(Func<Type, IDbContextWrapper, IRepository> resolver)
            {
                this._resolver = resolver;
            }
		}

		public partial class BaseRepository : DbRepository<Base>, IBaseRepository
		{
			public BaseRepository(IDbContextWrapper wrapper)
				: base(wrapper)
			{		
			}	
		}
		public partial class DerivedARepository : DbRepository<DerivedA, Base>, IDerivedARepository
		{
			public DerivedARepository(IDbContextWrapper wrapper)
				: base(wrapper)
			{		
			}	
		}
		public partial class DerivedBRepository : DbRepository<DerivedB, Base>, IDerivedBRepository
		{
			public DerivedBRepository(IDbContextWrapper wrapper)
				: base(wrapper)
			{		
			}	
		}
		public partial class SimpleRepository : DbRepository<Simple>, ISimpleRepository
		{
			public SimpleRepository(IDbContextWrapper wrapper)
				: base(wrapper)
			{		
			}	
		}
	}

	#endregion
}

